package com.czy.basecommon.utils.tools;

import java.io.File;

/*
 * Added by danny 20190919
 */
public class FileHelper {
    //String localDB = Constants.ROOT_PATH + Constants.ROOT_DIR_NAME + Constants.DB_DIR_NAME + "/"+ req.getCWRNo() + "-" +  req.getStartDate().replace("/","") + ".db";
    /*
     * 判断文件是否存在
     */
    public static boolean isExist(String path){
        File file = new File(path);
        return file.exists();
    }

    public static boolean createDirectory(String path){
        try {
            File file = new File(path);
            if (!file.exists())
                file.mkdirs();
            return true;
        }catch (Exception ex){
            ex.printStackTrace();
            return false;
        }
    }

    public static boolean deleteFile(String path){
        try {
            File file = new File(path);
            if (!file.exists()) return true;
            return file.delete();
        }catch (Exception ex){
            ex.printStackTrace();
            return false;
        }
    }

    public static void deleteFiles(File file) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                File f = files[i];
                deleteFiles(f);
            }
            //file.delete();//如要保留文件夹，只删除文件，请注释这行
        } else if (file.exists()) {
            file.delete();
        }
    }






}
